#include "process.h"

#define SIZE 101
#define STYLE '='



void FlushProcess(double total,double curr)
{
    if(curr > total)
        curr = total;
    
    char processbar[SIZE];
    memset(processbar,'\0',sizeof(processbar));
    double rate = curr / total * 100;
    for(int i = 0;i < (int)rate;i++)
        processbar[i] = STYLE;
    
    const string lable = "|/-\\";
    static int j = 0;
    printf("[%-100s] [%.2lf%%] [%c]\r",processbar,rate,lable[j++]);
    j %= lable.size();

    fflush(stdout);
}





void Process()
{
    const string stable2 = "|/-\\";
    int len = stable2.size();

    //cout << "i am process!" << endl;
    char processbar[SIZE];
    memset(processbar,0,sizeof(processbar));
    int cnt = 0;
    while(cnt<=100)
    {
        printf("[%-100s] [%d%%] [%c]\r",processbar,cnt,stable2[cnt % len]);
        fflush(stdout);
        processbar[cnt++] = STYLE;
        usleep(10000);
    }

    printf("\n");

}

